﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="teljekoormus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Teljekoormus))]
    public class TeljekoormusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ITeljekoormus clazz;
        
        public TeljekoormusSerializer(ITeljekoormus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("telje_nr");
            if (clazz.TeljeNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TeljeNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TeljeNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lubatud_teljekoormus");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.LubatudTeljekoormus))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("reg_teljekoormus");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.RegTeljekoormus))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "telje_nr")) {
                goto telje_nr;
            }
            else {
                if ((Reader.LocalName == "lubatud_teljekoormus")) {
                    goto lubatud_teljekoormus;
                }
                else {
                    if ((Reader.LocalName == "reg_teljekoormus")) {
                        goto reg_teljekoormus;
                    }
                    else {
                        return;
                    }
                }
            }
        telje_nr:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>teljekoormus>telje_nr");
            }
            clazz.TeljeNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("telje_nr")).Value;
            goto START;
        lubatud_teljekoormus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>teljekoormus>lubatud_teljekoormus");
            }
            clazz.LubatudTeljekoormus = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("lubatud_teljekoormus")).Value;
            goto START;
        reg_teljekoormus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>teljekoormus>reg_teljekoormus");
            }
            clazz.RegTeljekoormus = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("reg_teljekoormus")).Value;
            goto START;
        }
    }
}
